package com.example.studentmanager.Util;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Dbtool {
    private static  HikariDataSource dataSource;
    static {
        try {
            //
            HikariConfig config=new HikariConfig();
            config.setMaxLifetime(10000);
            config.setIdleTimeout(10000);
            config.setMaximumPoolSize(40);

        config.setDriverClassName("com.mysql.cj.jdbc.Driver");
            config.setUsername("root");
            config.setPassword("Zxd123456789.");
            config.setJdbcUrl("jdbc:mysql://localhost:3306/studentmanager?useUnicode=true&characterEncoding=utf8");
            dataSource=new HikariDataSource(config);
//配置  你的数据库
        } catch (Exception e){
            e.printStackTrace();
        }
    }
    public Dbtool(){

    }
    public  static  Connection getconnection(){
        try {
            return  dataSource.getConnection();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
